package culosic.mdpocket.android;
import android.graphics.*;
import android.content.*;

import java.io.InputStream;
import java.io.*;
import android.widget.*;

import culosic.mdpocket.markdown.R;


public class AppUtil
{
	private static String htmlPre = "<p>Markdown File Without Css</p>";
	private static boolean htmlPreRead = false;
	
	static Typeface getIconFont(Context context){
		return Typeface.createFromAsset(context.getAssets(), "fontawesome-webfont.ttf");
	}

	public static String getHtmlPre(Context context){
		if(!htmlPreRead){
			// 读取html-pre文件
			try {
				InputStream is = getHtmlPreRaw(context);
				InputStreamReader isr = new InputStreamReader(is, "utf-8");
				BufferedReader br = new BufferedReader(isr);
				StringBuilder sb = new StringBuilder();
				String str;
				while (null != (str = br.readLine())) {
					sb.append(str);
				}
				htmlPre = sb.toString();
				htmlPreRead = true;
				br.close();
				isr.close();
				is.close();
			} catch (Exception e) {
				Toast.makeText(context, R.string.error_app, Toast.LENGTH_SHORT).show();
			}
		}
		return htmlPre;
	}
	
    private static InputStream getHtmlPreRaw(Context context){
        return context.getResources().openRawResource(R.raw.markdown_pocket);
    }
}
